package com.hifar.plugins;

import com.deepoove.poi.data.TextRenderData;
import com.deepoove.poi.policy.AbstractRenderPolicy;
import com.deepoove.poi.policy.TextRenderPolicy;
import com.deepoove.poi.render.RenderContext;
import com.tssk.kylx.fw.utils.lang.StringUtils;
import org.apache.poi.xwpf.usermodel.XWPFRun;

import java.util.Objects;

/**
 * @Description 复选框渲染
 * @Author zhuWeiWei
 * @Date 2024/2/27 17:18
 */
public class TextCheckBoxRenderPolicy extends AbstractRenderPolicy<Object> {

    private String successStr = "☑";

    private String errorStr = "□";
    /**
     * 例如 设置为1 ，参数为1则为选中，否则不为选中
     */
    private String checkText = "true";


    @Override
    public void doRender(RenderContext<Object> context) throws Exception {
        Object data = context.getData();
        XWPFRun run = context.getRun();
        Boolean isCheck = Objects.equals(checkText, StringUtils.trimNull(data));
        if (isCheck) {
            TextRenderPolicy.Helper.renderTextRun(run, new TextRenderData(successStr));
        } else {
            TextRenderPolicy.Helper.renderTextRun(run, new TextRenderData(errorStr));
        }
    }

    public TextCheckBoxRenderPolicy() {

    }

    public TextCheckBoxRenderPolicy(String checkText) {
        this.checkText = checkText;
    }

    public TextCheckBoxRenderPolicy(String successStr, String errorStr) {
        this.successStr = successStr;
        this.errorStr = errorStr;
    }

    public TextCheckBoxRenderPolicy(String successStr, String errorStr, String checkText) {
        this.successStr = successStr;
        this.errorStr = errorStr;
        this.checkText = checkText;
    }
}
